package com.lm.boot.anntotation;

import java.lang.annotation.Annotation;
import java.lang.reflect.Method;

public class ParseAnn {

    public static void main(String[] args) {
        //1、使用类加载器加载类
        try {
            Class c = Class.forName("com.lm.boot.anntotation.Child");
            //2 找到类上面的注解
            boolean isExist = c.isAnnotationPresent(Description.class);
            if (isExist){
                //3 拿到注解实例
                Description de = (Description) c.getAnnotation(Description.class);
                System.out.println(de.value());
            }

            //4 找到方法上的注解
            Method[] ms = c.getMethods();
            for (Method m:ms) {
                if (m.isAnnotationPresent(Description.class)){
                    Description de = m.getAnnotation(Description.class);
                    System.out.println(de.value());
                }

            }
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }

    }
}
@Description("my custom ann class")
class Child{

    @Description("my custom ann method")
    public String getName(){
        return "hi";
    }
}